const mongoose = require("mongoose")

const schema = new mongoose.Schema(
    {
        username: { type: String, unique: true },
        password: {
            type: String,
            select: true, // 显示密码
            set(val) {
                return val
            },
        },
        email: { type: String, required: true },
        role: { type: String, enum: ['user', 'admin'], default: 'user' },
        // 引用camera表
        camera: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Camera' }],
        // 应用file表
        // file: [{ type: mongoose.Schema.Types.ObjectId, ref: 'File' }],
    },
    { timestamps: true }
)

module.exports = mongoose.model("User", schema, "user")